/****************************************************************************
*
*  ALi (Zhuhai) Corporation, All Rights Reserved. 2008 Copyright (C)
*
*  File: win_no_demo.c
*
*  Description: 
*              
*  History:
*      Date        	        Author             	Version     	Comment
*      2009/01/13        	Alan Song        	0.01   	        =======
*
****************************************************************************/

#include <sys_config.h>
#include <types.h>
#include <basic_types.h>
#include <mediatypes.h>
#include <api/libc/printf.h>
#include <api/libc/string.h>
#include <osal/osal.h>
#include <bus/hdmi/m36/hdmi_api.h>
#include <api/libosd/osd_lib.h>
#include <api/libchunk/chunk.h>

#include "osdobjs_def.h"

#include "string.id"
#include "images.id"
#include "osd_config.h"
#include "osd_rsc.h"
#include "control.h"
//#include "win_com_menu_define.h"
#include "win_com.h"
#include "menus_root.h"

/*******************************************************************************
* Objects declaration
*******************************************************************************/
#ifdef SUPPORT_DEO_HINT



extern TEXT_FIELD	   text_no_menu;
extern CONTAINER       g_win_no_menu;
#define OSD_HINT_REGION_WIDTH   256//416
#define OSD_HINT_REGION_HEIGHT  50
#define OSD_HINT_REGION_TOP     20 
#define OSD_HINT_REGION_LEFT    (680 - OSD_HINT_REGION_WIDTH)     


#define TXTN_SH_IDX   WSTL_TEXT_04_8BIT//WSTL_POP_TEXT_8BIT//WSTL_TEXT_13
#define TXTN_HL_IDX   WSTL_TEXT_04_8BIT//WSTL_POP_TEXT_8BIT//WSTL_BUTTON_02_FG
#define TXTN_SL_IDX   WSTL_TEXT_04_8BIT//WSTL_POP_TEXT_8BIT//WSTL_TEXT_13
#define TXTN_GRY_IDX  WSTL_TEXT_04_8BIT//WSTL_POP_TEXT_8BIT//WSTL_TEXT_14

#define CON_SH_IDX	WSTL_POP_WIN_01_8BIT//WSTL_TEXT_12
#define CON_HL_IDX	WSTL_POP_WIN_01_8BIT//WSTL_BUTTON_05
#define CON_HL1_IDX	WSTL_POP_WIN_01_8BIT//WSTL_BUTTON_05
#define CON_SL_IDX	WSTL_POP_WIN_01_8BIT//WSTL_TEXT_12
#define CON_GRY_IDX	WSTL_POP_WIN_01_8BIT//WSTL_TEXT_14


#define LDEF_CON(root, varCon,nxtObj,ID,IDl,IDr,IDu,IDd,l,t,w,h,hl,conobj,focusID)		\
    DEF_CONTAINER(varCon,root,nxtObj,C_ATTR_ACTIVE,0, \
    ID,IDl,IDr,IDu,IDd, l,t,w,h, CON_SH_IDX,CON_HL_IDX,CON_SL_IDX,CON_GRY_IDX,   \
    NULL,NULL,  \
    conobj, ID,1)
#define LDEF_TXT(root,varTxt,nxtObj,l,t,w,h,str)		\
    DEF_TEXTFIELD(varTxt,root,nxtObj,C_ATTR_ACTIVE,0, \
    0,0,0,0,0, l,t,w,h, TXTN_SH_IDX,TXTN_HL_IDX,TXTN_SL_IDX,TXTN_GRY_IDX,   \
    NULL,NULL,  \
    C_ALIGN_CENTER | C_ALIGN_VCENTER, 0,0,str,NULL)

#define LDEF_DEMO(root,varCon,nxtObj,varTxt,ID,IDu,IDd,l,t,w,h,\
						hl,str) \
    LDEF_CON(root,varCon,nxtObj,ID,ID,ID,IDu,IDd,l,t,w,h,hl,&varTxt,ID)   \
    LDEF_TXT(&varCon,varTxt,NULL,l,t,w,h,str)

LDEF_DEMO(NULL,g_win_no_menu,NULL,text_no_menu,1,0,0, \
       0,0,256,36,CON_HL_IDX,RS_NOMENU_HINT)

static BOOL  no_menu_hint = FALSE;

void DrawNoMenuHint()
{
	TEXT_FIELD* txt;
    OBJECT_HEAD* obj;
    obj = (OBJECT_HEAD*)&g_win_no_menu;

	txt = &text_no_menu;
	//OSD_SetTextFieldContent(txt, STRING_ID,(UINT32)RS_NOMENU_HINT);
	//OSD_SetTextFieldContent(txt, STRING_ANSI, (UINT32)"No OSD");

    OSD_DrawObject((POBJECT_HEAD)obj, C_UPDATE_ALL);
	
}
void NoMenuHintOnOff(BOOL flag)
{
	struct osd_device *osd_hint_dev;	 

	osd_hint_dev = (struct osd_device *)dev_get_by_name("OSD_M3327C_1");
	if(TRUE == flag && FALSE == no_menu_hint)
	{
		OSDDrv_ShowOnOff((HANDLE)osd_hint_dev,OSDDRV_ON);
		no_menu_hint = TRUE;
		//ap_draw_nomenu_hint();
	}
	else if(FALSE == flag && TRUE == no_menu_hint)
	{
		OSDDrv_ShowOnOff((HANDLE)osd_hint_dev,OSDDRV_OFF);
		no_menu_hint = FALSE;
	}
}


void ap_nomenu_hint_init()
{
	struct OSD_RegionInfo	osd_region_info;
	struct osd_device *osd_hint_dev;

	osd_hint_dev = (struct osd_device *)dev_get_by_name("OSD_M3327C_1");

	//osd_m3327c_detach((struct osd_device *) osd_hint_dev);
	
	OSD_DRIVER_CONFIG osd_config;
	MEMSET((void *)&osd_config,0,sizeof(OSD_DRIVER_CONFIG));
	osd_config.uMemBase = ((UINT32)MALLOC(0xF0020) & 0xFFFFFFE0) - (720 * OSD_HINT_REGION_TOP);//0x80780000;
	osd_config.uMemSize = 0xF000;
	osd_config.bStaticBlock = TRUE;
	osd_config.bDirectDraw = TRUE;
	osd_config.bCacheable = TRUE;
	osd_config.bVFilterEnable = FALSE;
	osd_config.bP2NScaleInNormalPlay = TRUE;
	osd_config.bP2NScaleInSubtitlePlay = TRUE;
	osd_config.uDViewScaleRatio[OSD_PAL][0] = 384;
	osd_config.uDViewScaleRatio[OSD_PAL][1] = 510;
	osd_config.uDViewScaleRatio[OSD_NTSC][0] = 384;
	osd_config.uDViewScaleRatio[OSD_NTSC][1] = 426;
	osd_config.af_par[0].id = 0;
	osd_config.af_par[0].vd = 1;
	osd_config.af_par[0].af = 1;
	osd_config.af_par[0].id = 1;
	osd_config.af_par[0].vd = 1;
	osd_config.af_par[0].af = 1;
	//osd_s36_attach("OSD_S36_0", &osd_config);
	osd_m33c_attach("OSD_M3327C_1", &osd_config);
	//osd_config.uMemBase = __MM_OSD_BK_ADDR2;
	//osd_config.bP2NScaleInNormalPlay = FALSE;
	//osd_s36_attach("OSD_S36_1", &osd_config);
	
}
void ap_draw_nomenu_hint()
{
	struct OSD_RegionInfo	osd_region_info;
	struct OSD_RscInfo		osd_rsc_info;
	struct osd_device *osd_hint_dev;
    HANDLE handle;
    UINT8  trans_color;
    OSD_RECT rect;
    extern HANDLE OSD_GetCurDeviceHandle(void);

    
	osd_hint_dev = (struct osd_device *)dev_get_by_name("OSD_M3327C_1");
    

	osd_region_info.osddev_handle = (HANDLE)osd_hint_dev;
	osd_region_info.tOpenPara.eMode = OSD_256_COLOR;
	osd_region_info.tOpenPara.uGAlphaEnable = IF_GLOBAL_ALPHA;
	osd_region_info.tOpenPara.uGAlpha = 0x0F;
	osd_region_info.tOpenPara.uPalletteSel = 0;
    osd_region_info.osdrect.uLeft = OSD_HINT_REGION_LEFT;
	osd_region_info.osdrect.uTop  = OSD_HINT_REGION_TOP;
	osd_region_info.osdrect.uWidth = OSD_HINT_REGION_WIDTH;
	osd_region_info.osdrect.uHeight = OSD_HINT_REGION_HEIGHT;
	osd_rsc_info.osd_get_lang_env = OSD_GetLangEnvironment;
	osd_rsc_info.osd_get_obj_info = OSD_GetObjInfo;
	osd_rsc_info.osd_get_rsc_data= OSD_GetRscObjData;
	osd_rsc_info.osd_rel_rsc_data= OSD_ReleaseObjData;
	osd_rsc_info.osd_get_font_lib = OSD_GetDefaultFontLib;
	osd_rsc_info.osd_get_win_style = OSDExt_GetWinStyle;
	osd_rsc_info.osd_get_str_lib_id = OSDExt_GetMsgLibId;
	#ifdef BIDIRECTIONAL_OSD_STYLE
	osd_rsc_info.osd_get_mirror_flag = OSD_GetMirrorFlag;
	#endif
	osd_rsc_info.ap_hk_to_vk = ap_hk_to_vk;
	osd_rsc_info.osd_get_thai_font_data = NULL;

    //OSDDrv_Open(osd_hint_dev,&osd_region_info.tOpenPara);
    osd_init_regionfill((struct osd_device *) osd_hint_dev);

    OSDDrv_ShowOnOff((HANDLE)osd_hint_dev,OSDDRV_OFF);
    OSDDrv_DeleteRegion((HANDLE)osd_hint_dev,0);
	//OSD_RegionInit(&osd_region_info,&osd_rsc_info);
    OSD_SmallRegionInit(&osd_region_info,&osd_rsc_info);
	OSDDrv_IoCtl((HANDLE)osd_hint_dev,OSD_IO_UPDATE_PALLETTE,0);
    //handle = g_osd_region_info.osddev_handle;
    //g_osd_region_info.osddev_handle = osd_hint_dev;
    trans_color = OSD_GetTransColor(osd_region_info.tOpenPara.eMode, FALSE);
    
    handle = OSD_GetCurDeviceHandle();
    OSD_SetDeviceHandle((HANDLE)osd_hint_dev);
    rect = osd_region_info.osdrect;
    rect.uLeft = rect.uTop = 0;
    DrawNoMenuHint();
    OSD_SetDeviceHandle(handle);
    //g_osd_region_info.osddev_handle = handle;
	//api_set_ui_scale(OSD_SRC_HD,OSD_REGION_RESET);
}
#endif

